#!/usr/bin/env bash
db_name=trending_topic
trending_topics=(\
    "topic_rank"\ 
    "body_building" "health"\
    "fashion" "cars" "daily_life"\
    "tech" "beautify_photo" "games"\
    "lovely_pet" "digital_device"\
    "joke" "music" "military"\
    "baby" "education" "realstate"\
    "constellation" "culture"\
    "government" "animation"\
    "call_for_creativity" "readings"\
    "food" "commonweal" "travel"\
    "sentiment" "finance" "movies"\
    "popular_science" "variety_show"\
    "tvshow" "stars" "sports" "society")
trtopic_local=(\
    'beijing' 'tianjin'\    
    'shijiazhuang' 'taiyuan'\
    'huhehaote' 'shengyang'\
    'changchun' 'haerbing'\   
    'shanghai'  'nanjing'\    
    'hangzhou'  'hefei'\      
    'fuzhou'    'nanchang'\   
    'jinan'     'zhengzhou'\  
    'wuhan'     'changsha'\   
    'guangzhou' 'nanning'\    
    'haikou'    'chongqing'\  
    'chengdu'   'guiyang'\    
    'kunming'   'lasa'\       
    'xian'      'lanzhou'\    
    'xining'    'yinchuan'\   
    'xinjiang'  'taiwan'\     
    'xianggang' 'aomen'\      
    'dalian'    'wuxi'\       
    'xiamen'    'qingdao'\    
    'suzhou')    



trtopic_schm=(\
    "id         integer," \
    "rank       integer,"\
    "name       varchar(100),"\
    "intro      varchar(280),"\
    "tags       varchar(50),"\
    "presenter  varchar(50),"\
    "presenter_id   varchar(20),"\
    "category       varchar(50),"\
    "district       varchar(20),"\
    "timestamp  varchar(14)"\
)
trtopic_statis_schm=(\
    "id         integer,"\
    "num_readings   integer,"\
    "num_discussion integer,"\
    "num_fans       integer,"\
    "timestamp  varchar(14)"\
)
psql <<__EOF
    create database $db_name
__EOF
for topic in ${trending_topics[@]}; do
    psql <<__EOF
    create table ${topic}_all (${trtopic_schm[@]});
    create table ${topic}_hot (${trtopic_schm[@]});
    create table ${topic}_all_statis (${trtopic_statis_schm[@]});
    create table ${topic}_hot_statis (${trtopic_statis_schm[@]});
__EOF
done
for topic in ${trtopic_local[@]}; do
    psql <<__EOF
    create table ${topic} (${trtopic_schm[@]});
    create table ${topic}_statis (${trtopic_statis_schm[@]});
__EOF
done



